package com.newenergy.wisehome.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.newenergy.wisehome.R;
import com.newenergy.wisehome.common.util.ImageUtil;
import com.newenergy.wisehome.data.bean.Scene;

import java.util.List;

/**
 *
 * Created by new on 2017/11/23.
 */

public class SceneModeAdapter extends  RecyclerArrayAdapter<Scene> {

    private Context mContext;

    public void refreshData(List<Scene> data) {
        clear();
        if (data != null) addAll(data);
        notifyDataSetChanged();
    }


    public SceneModeAdapter(Context context) {
        super(context);
        mContext=context.getApplicationContext();
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(parent);
    }


    private class ViewHolder extends BaseViewHolder<Scene> {

        private ImageView ivScene;
        private TextView tvScene;
        private LinearLayout llSceneSelect;


        public ViewHolder(ViewGroup parent) {
            super(parent, R.layout.scene_mode_item);
            ivScene = $(R.id.iv_scene);
            tvScene = $(R.id.tv_scene);
            llSceneSelect = $(R.id.ll_scene_select);
        }


        @Override
        public void setData(Scene data) {
            super.setData(data);
            int imageId = ImageUtil.getImageId(data.getIconName());

//            ivScene.setBackgroundResource(imageId);
            ivScene.setImageResource(imageId);
            tvScene.setText(data.getName());
            llSceneSelect.setSelected(data.isChecked());

        }
    }

}
